package com.rui.study.algorithm.P_提莫攻击;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-01-10 15:11
 **/
public class Solution {

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        int sum = duration;
        if (n == 0) {
            return 0;
        }
        for (int i = 1; i < n; i++) {
            int diff = timeSeries[i] - timeSeries[i-1];
            if (diff > duration)
                sum += duration;
            else {
                sum += diff;
            }
        }
        return sum ;
    }
}
